import React, {
    PureComponent
} from 'react';

import {
    Modal
} from './../../../components';

import Content from './content';

interface State {
    show:boolean
}

interface Props {
    onClose:Function
}

class Index extends PureComponent<Props,State>{
    handel:Function = () => null;
    private content:any = null;

    static defaultProps = {
        onClose:() => null
    }

    state = {
        show:false
    }

    public open = (func:Function) => {
        this.handel = func;
        this.setState({
            show:true
        })
    }

    public close = () => {
        const {
            onClose
        } = this.props;

        this.setState({
            show:false
        },() => onClose())
    }

    public submit = async () => {
        this.content.onSubmit();
    }

    render() {
        const {
            show
        } = this.state;

        return (
            <Modal
                show={show}
                portal={false}
                direction="top"
                onClose={this.close}
            >
                <Content
                    onFilter={this.handel}
                    ref={e => this.content=e}
                    onDialogClose={this.close}
                />
            </Modal>
        )
    }
}

export default Index;